<!--
    Desenvolvido pela Fábrica de Software do CESUPA.
    Todos os direitos reservados.

    @author Breno Leite
-->

<ui:component xmlns="http://www.w3.org/1999/xhtml"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:a4j="http://richfaces.org/a4j"
              xmlns:rich="http://richfaces.org/rich"
              xmlns:c="http://java.sun.com/jstl/core">

    <table align="center">
        <tr>
            <td>
                <a4j:region id="messagearea" rendered="#{MessageBean.applicationMessageActive}">
                    <div id="status" class="#{MessageBean.applicationMessage.messageType.name}">
                        <table>
                            <tr>
                                <td style="text-align:left;">
                                    <img border="0"
                                         src="#{facesContext.externalContext.request.contextPath}/images/icons/#{MessageBean.applicationMessage.messageType.name}-16x16.gif"
                                         alt="#{MessageBean.applicationMessage.messageType} icon"/>
                                </td>
                                <td>
                                    <h:outputText escape="false" value="#{MessageBean.applicationMessage.text}"/>
                                </td>
                                <td>
                                    <h:form>
                                        <h:outputLink rendered="#{!empty MessageBean.applicationMessage.fields}"
                                                      value="#" id="link">
                                            <h:graphicImage title="#{tooltipmessages.ViewDetails}"
                                                            url="/images/icons/details-16x16.gif"/>
                                            <rich:componentControl for="message-details-window"
                                                                   attachTo="link" operation="show"
                                                                   event="onclick"/>
                                        </h:outputLink>
                                        <h:outputText value=" "/>
                                        <a4j:commandLink id="hide-status-message-link">
                                            <a4j:actionparam name="username" action="null"
                                                             value="false"
                                                             assignTo="#{MessageBean.applicationMessageActive}"/>
                                            <a4j:support event="onclick" reRender="messagearea" />
                                            <h:graphicImage url="/images/icons/close-16x16.gif"
                                                            title="#{tooltipmessages.CloseMessage}"/>
                                            <rich:effect for="hide-status-message-link"
                                                         targetId="status" event="onclick"
                                                         type="DropOut" params="duration:0.5" />
                                        </a4j:commandLink>
                                    </h:form>
                                </td>
                            </tr>
                        </table>
                    </div>
                </a4j:region>
            </td>
        </tr>
    </table>

    <rich:modalPanel autosized="true" styleClass="window"
                     onshow="setFocusAtElement('status-message-form:status-message-window-close-button')"
                     id="message-details-window" height="250" width="550">
        <f:facet name="header">
            <h:panelGroup>
                <h:outputText value="#{words.ApplicationMessage}"></h:outputText>
            </h:panelGroup>
        </f:facet>
        <f:facet name="controls">
            <h:panelGroup>
                <h:form>
                    <h:commandLink title="#{tooltipmessages.CloseWindow}"
                                   id="hide-status-message-window-link">
                        <h:graphicImage alt="#{altmessages.CloseWindow}"
                                        value="/images/icons/close-16x16.gif"/>
                        <rich:componentControl for="message-details-window"
                                               attachTo="hide-status-message-window-link"
                                               operation="hide" event="onclick"/>
                    </h:commandLink>
                </h:form>
            </h:panelGroup>
        </f:facet>
        <table border="0" width="100%" class="#{MessageBean.applicationMessage.messageType.name}-message-main-area">
            <tr>
                <td width="64px">

                </td>
                <td style="padding:10px;">
                    <h:outputText escape="false" value="#{MessageBean.applicationMessage.text}"/>
                </td>
            </tr>
        </table>
        <div >
            <br />
            <table width="100%" border="0" style="font-size:12px;line-height:1.5em;">
                <c:forEach items="#{MessageBean.applicationMessage.fields}" var="field">
                    <tr style="border-bottom:dotted 1px black;">
                        <td valign="top" style="font-weight:bold;width:74px;">
                            #{field.key}
                        </td>
                        <td valign="top">
                            #{field.value}
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </div>
        <br />
        <div class="buttons" style="float:right;">
            <h:commandLink type="reset" id="status-message-window-close-button"
                           class="primarybutton">
                #{words.Close}
                <rich:componentControl for="message-details-window"
                                       attachTo="status-message-form:status-message-window-close-button"
                                       operation="hide" event="onclick"/>
            </h:commandLink>
        </div>
    </rich:modalPanel>
</ui:component>